#include "StudyJournal.h"
#include <QDebug>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPixmap>
#include <QBitmap>

StudyJournal::StudyJournal()
{
    //设置无边框
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground, true);

    //设置窗口大小
    this->resize(WinWidth,WinHeight);
    //qDebug("%d,%d\n",this->width(),this->height());
    this->setWindowIcon(QIcon("image/图标.jpg"));


    QGridLayout *pLayout = new QGridLayout(this);
    pLayout->addWidget(set,0,0);
    pLayout->addWidget(journal,1,0);
    pLayout->addWidget(content,5,0,1,5);
    pLayout->addWidget(hitCard,5,10);

    QPixmap setPix("image/设 置.png");
    set->setIcon(setPix);
    set->setIconSize(setPix.size());
    set->setMask(setPix.mask());

    this->setLabelFont();
    //journal->setParent(this);
    //journal->setText(QString("做桌面便签\n做桌面便签\n"));

    //hitCard->setText("打卡");
    connect(hitCard,&QPushButton::clicked,[=]{
        if(""!=content->text())
        {

            QString current_date =current_date_time.toString("MM.dd hh:mm:ss");
            QString str=journal->text()+"["+current_date+"]"+content->text()+"\n";
            journal->setText(str);
            content->setText("");
        }
    });

    connect(set,&QPushButton::clicked,[=]{
        emit setBottom();
    });

    QPixmap pixdaka("image/打卡.png");
    //hitCard->resize(100,100);
    hitCard->setIcon(pixdaka);
    hitCard->setIconSize(pixdaka.size());
    hitCard->setMask(pixdaka.mask());


    this->update();
}

StudyJournal::~StudyJournal()
{

}

void StudyJournal::setLabelFont()
{
    QFont winFont;
    winFont.setFamily("宋体");
    winFont.setPointSize(labelSize);
    winFont.setBold(labelBold);
    winFont.setItalic(labelItalic);
    QString color=QString::asprintf("color:rgb(%d,%d,%d);qproperty-alignment: 'AlignTop | AlignLeft';",fontR,fontG,fontB);
    //qDebug("%d,%d,%d\n",fontR,fontG,fontB);
    journal->setStyleSheet(color);
    journal->setFont(winFont);
}

void StudyJournal::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    //设置透明背景色
    painter.fillRect(this->rect(),QColor(46,46,46,transparency));
    this->setLabelFont();
    content->setStyleSheet("border:1px solid rgb(180,180,180);"
                           "background:rgb(230,230,230,50);"
                           "border-radius:4px;");

}

void StudyJournal::mousePressEvent(QMouseEvent *e)
{
    isPressScreen=true;
    mouseX = e->x();
    mouseY = e->y();
}

void StudyJournal::mouseMoveEvent(QMouseEvent *e)
{
    if(true==isPressScreen)
    {
        int x = this->x() + e->x();
        int y = this->y() + e->y();
        move(x - mouseX,y - mouseY);
    }
}

void StudyJournal::mouseReleaseEvent(QMouseEvent *e)
{
    isPressScreen = false;
}


